package com.zhengtoudai.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.zhengtoudai.R;
import com.zhengtoudai.ui.bean.DelegationNominis;
import com.zhengtoudai.util.DecimalFormatUtils;
import com.zhengtoudai.util.DensityUtil;
import com.zhengtoudai.view.recyclerview.RecyclerViewAdapter;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 债权转让适配器
 * author:xiejingwen
 */
public class DelegatioNominisAdapter extends RecyclerViewAdapter<DelegatioNominisAdapter.ViewHolder, DelegationNominis.ResultEntity.ListEntity> {

    private Context context;

    public DelegatioNominisAdapter() {

    }

    @Override
    public ViewHolder mOnCreateViewHolder(ViewGroup parent, int viewType) {
        context = parent.getContext();
        View view = LayoutInflater.from(context).inflate(R.layout.list_item_transfer, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void mOnBindViewHolder(ViewHolder holder, int position) {
        if (position==data.size()-1){
            holder.itemView.setPadding(DensityUtil.dip2px(context,10),DensityUtil.dip2px(context,10),DensityUtil.dip2px(context,10),DensityUtil.dip2px(context,10));
        }else{
            holder.itemView.setPadding(DensityUtil.dip2px(context,10),DensityUtil.dip2px(context,10),DensityUtil.dip2px(context,10),0);
        }
        holder.mTvTitle.setText(data.get(position).getBorrowTitle());
        holder.mTvLv.setText(data.get(position).getAnnualInterestRate()+"%");
        holder.mTvEr.setText(DecimalFormatUtils.formatMoney(data.get(position).getTotalAmount()+"",2)+"元");
        holder.mTvJia.setText(DecimalFormatUtils.formatMoney(data.get(position).getTransferMoney()+"",2)+"元");

        String status = "";
        int transferCode=data.get(position).getTransferStatus();
        int tenderCode=data.get(position).getTenderStatus();
        if (transferCode==0){
            status="等待审核";
        }else if (transferCode==1){
            status="认购中";
        }else if (transferCode==2){
            status="转让成功";
        }else if (transferCode==3){
            status="转让失败";
        }else if (transferCode==4){
            status="审核不通过";
        }else{
            if (tenderCode==2){
                status="复审未通过";
            }else if (tenderCode==3){
                status="还款中";
            }else if (tenderCode==4){
                status="还款成功";
            }else if (tenderCode==5){
                status="逾期";
            }else if (tenderCode==7){
                status="已转让";
            }else if (tenderCode==8){
                status="已赎回";
            }
        }

        holder.mTvZhuang.setText(status);
        if (transferCode==3||transferCode==4||transferCode==5&&tenderCode==3){
            holder.mTvTitleRight.setText("转让");
            holder.mTvTitleRight.setVisibility(View.VISIBLE);
        }else{
            holder.mTvTitleRight.setVisibility(View.GONE);
            holder.mTvTitleRight.setText("--");
        }

    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.tv_title)
        TextView mTvTitle;
        @Bind(R.id.tv_title_right)
        TextView mTvTitleRight;
        @Bind(R.id.tv_lv)
        TextView mTvLv;
        @Bind(R.id.tv_zhuang)
        TextView mTvZhuang;
        @Bind(R.id.tv_jia)
        TextView mTvJia;
        @Bind(R.id.tv_er)
        TextView mTvEr;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
